package club.janna.hello.bootstrap;

import club.janna.hello.constants.Values;
import org.yaml.snakeyaml.Yaml;
import java.io.FileInputStream;

/**
 * 引导器
 * Created by guopanbo on 18/1/9.
 */
public class Bootstrap {

    /**
     * 加载配置
     * @param runMode
     * @return
     */
    private static boolean loadProfile(String runMode) {
        Yaml yaml = new Yaml();
        try {
            Values values = yaml.loadAs(new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("setting-" + runMode + ".yml").getPath()), Values.class);
            System.out.println(values.getDatabase());
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    /**
     * 程序启动入口
     * @param args
     */
    public static void main(String[] args) {
        String runMode;
        if(args == null || args.length == 0 || args[0] == null || "".equals(args[0].trim()))
            runMode = "dev";
        else
            runMode = args[0];

        if(!loadProfile(runMode))
            throw new RuntimeException("load profile failed");
    }
}
